package com.syxp.pda.action.standard;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.syxp.pda.core.web.action.BaseAction;
import com.syxp.pda.entity.standard.DeviceRunState;
import com.syxp.pda.service.standard.DeviceRunStateService;

public class DeviceRunStateAction extends BaseAction {
	@Resource
	private DeviceRunStateService deviceRunStateService;
	
	private int deviceRunStateCode;
	private DeviceRunState deviceRunState;
	
	public String load() {
		List list = new ArrayList(); 
		try {
			List<DeviceRunState> deviceRunStates = this.deviceRunStateService.getDao().getAll();
			for(DeviceRunState o: deviceRunStates) {
				Map map = new HashMap();
				map.put("deviceRunStateName", o.getDeviceRunStateName());
				map.put("deviceRunStateCode", o.getDeviceRunStateCode());
				list.add(map);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		this.jsonString = this.gson.toJson(list);
		System.out.println(this.jsonString);
		return SUCCESS;
	}
	
	public String save() {
		try {
			this.deviceRunStateService.addService(this.deviceRunState);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}
	
	public String delete() {
		try {
			this.deviceRunStateService.removeService(this.deviceRunStateCode);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}
	
	public String update() {
		try {
			this.deviceRunStateService.updateService(this.deviceRunState);
			this.jsonString="{success:true}" ;
		} catch(Exception e) {
			e.printStackTrace();
			this.jsonString="{success:false}" ;
		}
		return SUCCESS;
	}

	/**
	 * @return the deviceRunStateService
	 */
	public DeviceRunStateService getDeviceRunStateService() {
		return deviceRunStateService;
	}

	/**
	 * @param deviceRunStateService the deviceRunStateService to set
	 */
	public void setDeviceRunStateService(DeviceRunStateService deviceRunStateService) {
		this.deviceRunStateService = deviceRunStateService;
	}

	/**
	 * @return the deviceRunStateCode
	 */
	public int getDeviceRunStateCode() {
		return deviceRunStateCode;
	}

	/**
	 * @param deviceRunStateCode the deviceRunStateCode to set
	 */
	public void setDeviceRunStateCode(int deviceRunStateCode) {
		this.deviceRunStateCode = deviceRunStateCode;
	}

	/**
	 * @return the deviceRunState
	 */
	public DeviceRunState getDeviceRunState() {
		return deviceRunState;
	}

	/**
	 * @param deviceRunState the deviceRunState to set
	 */
	public void setDeviceRunState(DeviceRunState deviceRunState) {
		this.deviceRunState = deviceRunState;
	}
}
